<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl"/>

    <script>
        $(function () {

            $(".changeBtn").click(function () {
                //清除模态框中的表单
                $("#editForm").clearForm(true);

                var json = $(this).data("json")
                $("#editForm input[name='id']").val(json.id)
                $("#editForm input[name='name']").val(json.name)
                $("#editForm select[name='strategy.id']").val(json.strategyId)
                $("#editForm input[name='sequence']").val(json.sequence)
                //因为在strategyCatalog中,state是boolean类型,所以要加+""
                $("#editForm select[name='state']").val(json.state+"")

                $("#inputModal").modal('show')
            })

            //新增事件
            $("#inputBtn").click(function () {
                $("#editForm").clearForm(true);
                $("#inputModal").modal('show')
            })

            $("#saveBtn").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    if (data.success) {
                        window.location.reload()
                    }
                })
            })

        })
    </script>


</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
        <#--设置当前要回显当前菜单,必须在载人菜单前完成设置-->
            <#assign menu="strategyCatalog"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略分类管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <div class="form-group">
                    <label class="col-sm-5 control-label">攻略搜索</label>
                    <div class="col-sm-6">
                        <select id="strategyId" class="form-control" autocomplete="off" name="strategyId">
                            <option value="-1">--请选择--</option>
                            <#list Strategys as s>
                                <option value="${s.id}">${s.title}</option>
                            </#list>
                        </select>
                        <script>
                            $("#strategyId").val(${qo.strategyId!})
                        </script>
                    </div>
                </div>
                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <button id="inputBtn" type="button" class="btn btn-success">
                    <span class="glyphicon glyphicon-plus"></span> 添加攻略分类
                </button>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>分类名称</th>
                    <th>所属攻略</th>
                    <th>排序</th>
                    <th>状态</th>
                    <th></th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity.name!}</td>
                        <td>${(entity.strategy.title)!}</td>
                        <td>${entity.sequence!}</td>
                        <td>${entity.stateName!}</td>
                        <td>
                            <a href="javaScript:;" class="changeBtn" data-json='${entity.jsonString}'>修改</a>
                        </td>
                    </tr>
                </#list>
            </table>
           <#include "../common/page.ftl"/>
        </div>
    </div>
</div>

<#--模态框-->
<div id="inputModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" method="post" action="/strategyCatalog/save.do"
                      enctype="multipart/form-data" style="margin: -3px 118px">
                    <input  type="hidden" name="id"/>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">分类名称</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control"  name="name" placeholder="分类名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属攻略</label>
                        <div class="col-sm-6">
                            <select name="strategy.id" class="form-control">
                                <#list Strategys as s >
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">排序</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control"  name="sequence" placeholder="排序号码">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态</label>
                        <div class="col-sm-6">
                            <select id="state" class="form-control" autocomplete="off" name="state">
                                <option value="true">启用</option>
                                <option value="false">禁用</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>

</body>
</html>